package com.spring.schedule_system.controller;


import cn.hutool.core.date.StopWatch;

import com.spring.schedule_system.dengxiaojiao.util.LyIdUtils;
import com.spring.schedule_system.dengxiaojiao.util.OptResult;
import com.szlanyou.api.annotation.CryptoParam;
import com.szlanyou.api.annotation.CryptoRequest;
import io.seata.rm.tcc.api.BusinessActionContext;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;
import java.util.Objects;


@Component
public class VenBuDeliveryOrderSaveManagerImpl implements VenBuDeliveryOrderSaveManager {

	@Transactional
	@Override
	@CryptoRequest(spels = "#info")
	public OptResult deliveryPrepare(@CryptoParam Map<String, Object> map, BusinessActionContext context) {
//		TransactionLogUtil.log(context, map, LyIdUtils.genId());

		return new OptResult();
	}

	@Override
	public void deliveryCommit(BusinessActionContext context) {
//		VenBuDeliveryOrderSaveManagerDomainIn inInfo = TransactionLogUtil.getLog(context, VenBuDeliveryOrderSaveManagerDomainIn.class).getRows();
//		//执行事务
//		venBuDeliveryOrderSaveManagerImpl.handledeliveryCommit(context);
//		//释放预留
//		//清除交车中缓存数量
//		TransactionRedisUtil.StringOps.incrBy(inInfo.getAllDeliveryKey(), -1);
//		TransactionRedisUtil.StringOps.incrBy(inInfo.getCarDeliveryKey(), -1);
//		TransactionRedisUtil.StringOps.incrBy(inInfo.getDlrDeliveryKey(), -1);
	}
	
	@Transactional
//	@CdcIntercept(sourceCode = "交车作业venBuDeliveryOrderSave:deliveryCommit")
	public void handledeliveryCommit(BusinessActionContext context) {
		StopWatch sw = new StopWatch("交车耗时");
		sw.start();
//		VenBuDeliveryOrderSaveManagerDomainIn inInfo = TransactionLogUtil.getLog(context, VenBuDeliveryOrderSaveManagerDomainIn.class).getRows();

		sw.stop();
		System.out.println("oms交车commit：" + sw.getTotalTimeSeconds() + "秒");
		log.pfmlog((long) sw.getTotalTimeSeconds(),"秒 oms交车commit");
	}

	@Override
	public void deliveryRollback(BusinessActionContext context) {
//		VenBuDeliveryOrderSaveManagerDomainIn inInfo = TransactionLogUtil.getLog(context, VenBuDeliveryOrderSaveManagerDomainIn.class).getRows();
//		//释放预留
//		//清除交车中缓存数量
//		TransactionRedisUtil.StringOps.incrBy(inInfo.getAllDeliveryKey(), -1);
//		TransactionRedisUtil.StringOps.incrBy(inInfo.getCarDeliveryKey(), -1);
//		TransactionRedisUtil.StringOps.incrBy(inInfo.getDlrDeliveryKey(), -1);
	}

}
